package ModelLayer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

import ModelLayer.Enums.CustomerType;

/**
 * This Class represent the Customer
 * @author frankeskelund, Kim Dam Gr�nh�j
 *
 */
public class Customer extends Person implements Serializable{
		
		private static final long serialVersionUID = 5162389995108201250L;
		
		private ArrayList<Sale> purchases;
		private ArrayList<Discount> discounts;
		private CustomerType customerType;

		public Customer(CustomerType customerType, String name, String address, String phoneNumber, String email, String signUpDate) 
		{
			super(name, address, phoneNumber, email, signUpDate);
			this.customerType = customerType;
			this.purchases = new ArrayList<Sale>();
			this.discounts = new ArrayList<Discount>();
		}
		
		public Customer()
		{
			super();
		}

		/**
		 * Gets the Customer type for this customer
		 * @return Customer there contains the customer type
		 */
		
		public CustomerType getCustomerType() {
			return customerType;
		} 
		
		public ArrayList<Discount> getDiscounts()
		{
			return discounts;
		}
		
		/**
		 * An ArrayList for storing the sales of customers
		 * @param customerSale is added to ArrayList sale
		 */
		public void addSale(Sale customerSale) {
	        this.purchases.add(customerSale);
	    }
		
		/**
		 * An ArrayList for storing the discounts of customer
		 * @param discount is added to ArrayList discount
		 */
		public void addDiscount(Discount discount) {
			this.discounts.add(discount);
	    }
		/**
		 * With this method you can find a product in partorders by product number
		 * - using search pattern
		 * @param productNumber Insert int number
		 * @return Product object
		 */
		public Product searchProduct(int productNumber)
		{
			Boolean found = false;	
			int i = 0;
			Product foundProduct = null;
			
			while (!found && this.discounts.size() > i)
			{
				Discount current = this.discounts.get(i);
				
				if (current.getProduct() != null && current.getProduct().getProductNumber() == productNumber)
				{
					found = true;
					foundProduct = current.getProduct();
				} else {
					i++;
				}
			}
			
			return foundProduct;
		}
		
		/**
		 * With this method you can find a Product in PartOrders and remove it
		 * - This method use search pattern
		 * @param productNumber insert int product number
		 */
		public void removeProduct(int productNumber)
		{
			Boolean found = false;	
			
			Iterator<Discount> iDiscount = this.discounts.iterator();
			while (!found && iDiscount.hasNext())
			{
				Discount current = iDiscount.next();
				
				if (current.getProduct() != null && current.getProduct().getProductNumber() == productNumber)
				{
					found = true;
					iDiscount.remove();
				}
			}
		}

}
